// C# ResultsetFields fields = new ResultsetFields(2); fields.DefineField(CustomerFieldIndex.Country, 0, "Country"); fields.DefineField(CustomerFieldIndex.CustomerID, 1, "AmountCustomers"); fields[1].AggregateFunctionToApply = AggregateFunction.CountDistinct;
' VB.NET Dim fields As New ResultsetFields(2) fields.DefineField(CustomerFieldIndex.Country, 0, "Country") fields.DefineField(CustomerFieldIndex.CustomerID, 1, "AmountCustomers") fields(1).AggregateFunctionToApply = AggregateFunction.CountDistinct
AggregateFunction value | Description | SQL | Not on | Remarks |
None | No aggregate function applied (default) | Just the fieldname, no wrapper function | ||
Avg | Calculates the average value for the field. | AVG(field) | works on numeric fields (decimal / int / float / byte / etc.) only | |
AvgDistinct | Calculates the average value for the distinct values for field. | AVG(DISTINCT field) | Access | works on numeric fields (decimal / int / float / byte / etc.) only |
Count | Calculates the number of rows for field. | COUNT(field) | ||
CountDistinct | Calculates the number of rows with distinct values for field. | COUNT(DISTINCT field) | Access | |
CountRow | Calculates the number of rows. | COUNT(*) | ||
Max | Calculates the max value for field. | MAX(field) | works on numeric fields (decimal / int / float / byte / etc.) only | |
Min | Calculates the min value for field. | MIN(field) | works on numeric fields (decimal / int / float / byte / etc.) only | |
Sum | Calculates the sum of all values of field. | SUM(field) | works on numeric fields (decimal / int / float / byte / etc.) only | |
SumDistinct | Calculates the sum of all distinct values of field. | SUM(DISTINCT field) | works on numeric fields (decimal / int / float / byte / etc.) only | |
StDev | Calculates statistical standard deviation for the values of field. | SqlServer: STDEV(field) Oracle: STDDEV(field) Access: STDEV(field) |
Firebird | works on floating point fields (float / single / etc.) only |
StDevDistinct | Calculates statistical standard deviation for the distinct values of field. | Oracle: STDDEV(DISTINCT field) | SqlServer, Access, Firebird | works on floating point fields (float / single / etc.) only |
Variance | Calculates statistical variance for the values of field. | SqlServer: VAR(field) Oracle: VARIANCE(field) Access: VAR(field) |
Firebird | works on floating point fields (float / single / etc.) only |
VarianceDistinct | Calculates statistical variance over the distinct values of field. | Oracle: VARIANCE(DISTINCT field) | SqlServer, Access, Firebird | works on floating point fields (float / single / etc.) only |
// C# OrderDetailsCollection orderDetails = new OrderDetailsCollection(); decimal orderPrice = (decimal)orderDetails.GetScalar(OrderDetailsFieldIndex.OrderId, (OrderDetailsFields.Quantity * OrderDetailsFields.UnitPrice), AggregateFunction.Sum, (OrderDetailsFIelds.OrderId == 10254));
' VB.NET .NET 1.x Dim orderDetails As New OrderDetailsCollection() Dim productPriceExpression As IExpression = New Expression( _ OrderDetailsFields.Quantity, ExOp.Mul, OrderDetailsFields.UnitPrice)) Dim filter As IPredicate = New FieldCompareValuePredicate(OrderDetailsFields.OrderId, ComparisonOperator.Equal, 10254) Dim orderPrice As Decimal = CDec(orderDetails.GetScalar(OrderDetailsFieldIndex.OrderId, _ productPriceExpression, AggregateFunction.Sum, filter))
' VB.NET .NET 2.0 Dim orderDetails As New OrderDetailsCollection() Dim orderPrice As Decimal = CDec(orderDetails.GetScalar(OrderDetailsFieldIndex.OrderId, _ (OrderDetailsFields.Quantity * OrderDetailsFields.UnitPrice), AggregateFunction.Sum, _ (OrderDetailsFIelds.OrderId == 10254)))
// C# DataAccessAdapter adapter = new DataAccessAdapter(); decimal orderPrice = (decimal)adapter.GetScalar(OrderDetailsFields.OrderId, (OrderDetailsFields.Quantity * OrderDetailsFields.UnitPrice), AggregateFunction.Sum, (OrderDetailsFIelds.OrderId == 10254));
' VB.NET .NET 1.x Dim adapter As DataAccessAdapter = New DataAccessAdapter() Dim productPriceExpression As IExpression = New Expression( _ OrderDetailsFields.Quantity, ExOp.Mul, OrderDetailsFields.UnitPrice) Dim filter As IPredicate = New FieldCompareValuePredicate(OrderDetailsFields.OrderId, Nothing, ComparisonOperator.Equal, 10254) Dim orderPrice As Decimal = CDec(adapter.GetScalar(OrderDetailsFields.OrderId, _ productPriceExpression, AggregateFunction.Sum, filter))
' VB.NET .NET 2.0 Dim adapter As DataAccessAdapter = New DataAccessAdapter() Dim orderPrice As Decimal = CDec(adapter.GetScalar(OrderDetailsFields.OrderId, (OrderDetailsFields.Quantity * OrderDetailsFields.UnitPrice), AggregateFunction.Sum, (OrderDetailsFIelds.OrderId == 10254)))
-- SQL SELECT OrderID, ProductID, (UnitPrice * Quantity) AS RowTotal FROM [Order Details]
// C# ResultsetFields fields = new ResultsetFields(3); fields.DefineField(OrderDetailsFields.OrderID, 0); fields.DefineField(OrderDetailsFields.ProductID, 1); fields.DefineField(new EntityField("RowTotal", (OrderDetailsFields.UnitPrice * OrderDetailsFields.Quantity)), 2); DataTable results = new DataTable(); TypedListDAO dao = new TypedListDAO(); dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);
' VB.NET Dim fields As New ResultsetFields(3) fields.DefineField(OrderDetailsFields.OrderID, 0) fields.DefineField(OrderDetailsFields.ProductID, 1) fields.DefineField(New EntityField("RowTotal", _ New Expression(OrderDetailsFields.UnitPrice, ExOp.Mul, OrderDetailsFields.Quantity)), 2) Dim results As New DataTable() Dim dao As New TypedListDAO() dao.GetMultiAsDataTable(fields, results, 0, Nothing, Nothing, Nothing, True, Nothing, Nothing, 0, 0)
// C# ResultsetFields fields = new ResultsetFields(3); fields.DefineField(OrderDetailsFields.OrderID, 0); fields.DefineField(OrderDetailsFields.ProductID, 1); fields.DefineField(new EntityField2("RowTotal", (OrderDetailsFields.UnitPrice * OrderDetailsFields.Quantity)), 2); DataTable results = new DataTable(); DataAccessAdapter adapter = new DataAccessAdapter(); adapter.FetchTypedList(fields, results, null);
' VB.NET Dim fields As New ResultsetFields(3) fields.DefineField(OrderDetailsFields.OrderID, 0) fields.DefineField(OrderDetailsFields.ProductID, 1) fields.DefineField(New EntityField2("RowTotal", _ New Expression(OrderDetailsFields.UnitPrice, ExOp.Mul, OrderDetailsFields.Quantity)), 2) Dim results As New DataTable() Dim adapter As New DataAccessAdapter() adapter.FetchTypedList(fields, results, Nothing)
// C# IExpression leftOperand = new Expression(MyEntityFields.Field1, ExOp.Add, MyEntityFields.Field2); IExpression rightOperand = new Expression( MyEntityFields.Field3, ExOp.Mul, MyEntityFields.Field4); EntityField field = MyEntityFields.Field1.SetExpression(leftOperand); IPredicate filter = FieldCompareExpressionPredicate(field, ExOp.GreaterThan, rightOperand); // which is equal to: IPredicate filter = ((MyEntityFields.Field1 + MyEntityFields.Field2) > MyEntityFields.Field3 * MyEntityFields.Field4));
' VB.NET Dim leftOperand As New Expression(MyEntityFields.Field1, ExOp.Add, MyEntityFields.Field2) Dim rightOperand As New Expression(MyEntityFields.Field3, ExOp.Mul, MyEntityFields.Field4) Dim field As EntityField = MyEntityFields.Field1.SetExpression(leftOperand) Dim filter As IPredicate = FieldCompareExpressionPredicate(field, ExOp.GreaterThan, rightOperand) ' which is equal to (VB.NET 2005) Dim filter As IPredicate = ((MyEntityFields.Field1 + MyEntityFields.Field2) > _ MyEntityFields.Field3 * MyEntityFields.Field4))
// C# IExpression leftOperand = new Expression(MyEntityFields.Field1, ExOp.Add, MyEntityFields.Field2); IExpression rightOperand = new Expression( MyEntityFields.Field3, ExOp.Mul, MyEntityFields.Field4); IEntityField2 field = MyEntityFields.Field1.SetExpression(leftOperand); IPredicate filter = FieldCompareExpressionPredicate(field, null, ExOp.GreaterThan, rightOperand); // which is equal to: IPredicate filter = ((MyEntityFields.Field1 + MyEntityFields.Field2) > MyEntityFields.Field3 * MyEntityFields.Field4));
' VB.NET Dim leftOperand As New Expression(MyEntityFields.Field1, ExOp.Add, MyEntityFields.Field2) Dim rightOperand As New Expression(MyEntityFields.Field3, ExOp.Mul, MyEntityFields.Field4) Dim field As EntityField2 = MyEntityFields.Field1.SetExpression(leftOperand) Dim filter As IPredicate = FieldCompareExpressionPredicate(field, Nothing, ExOp.GreaterThan, rightOperand) ' which is equal to (VB.NET 2005) Dim filter As IPredicate = ((MyEntityFields.Field1 + MyEntityFields.Field2) > _ MyEntityFields.Field3 * MyEntityFields.Field4))
// C# EmployeeEntity employee = new EmployeeEntity(); employee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)); EmployeeCollection employees = new EmployeeCollection(); // no filter is specified, everybody gets 10% extra, but you could of course // specify a filter to limit the scope of the update. employees.UpdateMulti(employee, null);
' VB.NET .NET 1.x Dim updateExpression As IExpression = New Expression( _ EmployeeFields.Salary, ExOp.Add, New Expression( _ EmployeeFields.Salary, ExOp.Mul, 0.1f))) Dim employee As New EmployeeEntity() employee.Fields(CInt(EmployeeFieldIndex.Salary)).ExpressionToApply = updateExpression Dim employees As New EmployeeCollection() ' no filter is specified, everybody gets 10% extra, but you could of course ' specify a filter to limit the scope of the update. employees.UpdateMulti(employee, Nothing)
' VB.NET .NET 2.0 Dim employee As New EmployeeEntity() employee.Fields(CInt(EmployeeFieldIndex.Salary)).ExpressionToApply = _ (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)) Dim employees As New EmployeeCollection() ' no filter is specified, everybody gets 10% extra, but you could of course ' specify a filter to limit the scope of the update. employees.UpdateMulti(employee, Nothing)
// C# EmployeeEntity employee = new EmployeeEntity(); employee.Fields[(int)EmployeeFieldIndex.Salary].ExpressionToApply = (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)); DataAccessAdapter adapter = new DataAccessAdapter(); // no filter is specified, everybody gets 10% extra, but you could of course // specify a filter to limit the scope of the update. adapter.UpdateEntitiesDirectly(employee, null);
' VB.NET .NET 1.x Dim updateExpression As IExpression = New Expression( _ EmployeeFields.Salary, ExOp.Add, New Expression( _ EmployeeFields.Salary, ExOp.Mul, 0.1f))) Dim employee As New EmployeeEntity() employee.Fields(CInt(EmployeeFieldIndex.Salary)).ExpressionToApply = updateExpression Dim adapter As DataAccessAdapter = New DataAccessAdapter() ' no filter is specified, everybody gets 10% extra, but you could of course ' specify a filter to limit the scope of the update. adapter.UpdateEntitiesDirectly(employee, Nothing)
' VB.NET .NET 2.0 Dim employee As New EmployeeEntity() employee.Fields(CInt(EmployeeFieldIndex.Salary)).ExpressionToApply = _ (EmployeeFields.Salary + (EmployeeFields.Salary * 0.01f)) Dim adapter As DataAccessAdapter = New DataAccessAdapter() ' no filter is specified, everybody gets 10% extra, but you could of course ' specify a filter to limit the scope of the update. adapter.UpdateEntitiesDirectly(employee, Nothing)
-- SQL SELECT CustomerID, ( SELECT COUNT(*) FROM Orders WHERE CustomerID = Customers.CustomerID ) AS NumberOfOrders FROM Customers
// C# ResultsetFields fields = new ResultsetFields(2); fields.DefineField(CustomerFields.CustomerID, 0); fields.DefineField(new EntityField("NumberOfOrders", new ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), (CustomerFields.CustomerId == OrderFields.CustomerId))), 1); DataTable results = new DataTable(); TypedListDAO dao = new TypedListDAO(); dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);
' VB.NET .NET 1.x Dim fields As New ResultsetFields(2) fields.DefineField(CustomerFields.CustomerID, 0) fields.DefineField(New EntityField("NumberOfOrders", _ New ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), _ New FieldCompareExpressionPredicate(CustomerFields.CustomerId, ComparisonOperator.Equal, _ New Expression(OrderFields.CustomerId)))), 1) Dim results As New DataTable() Dim dao As New TypedListDAO() dao.GetMultiAsDataTable(fields, results, 0, Nothing, Nothing, Nothing, True, Nothing, Nothing, 0, 0)
' VB.NET .NET 2.0 Dim fields As New ResultsetFields(2) fields.DefineField(CustomerFields.CustomerID, 0) fields.DefineField(New EntityField("NumberOfOrders", _ New ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), _ (CustomerFields.CustomerId = OrderFields.CustomerId))), 1) Dim results As New DataTable() Dim dao As New TypedListDAO() dao.GetMultiAsDataTable(fields, results, 0, Nothing, Nothing, Nothing, True, Nothing, Nothing, 0, 0)
// C# ResultsetFields fields = new ResultsetFields(2); fields.DefineField(CustomerFields.CustomerID, 0); fields.DefineField(new EntityField2("NumberOfOrders", new ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), (CustomerFields.CustomerId == OrderFields.CustomerId))), 1); DataTable results = new DataTable(); DataAccessAdapter adapter = new DataAccessAdapter(); adapter.FetchTypedList(fields, results, null);
' VB.NET .NET 1.x Dim fields As New ResultsetFields(2) fields.DefineField(CustomerFields.CustomerID, 0) fields.DefineField(New EntityField2("NumberOfOrders", _ New ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), _ New FieldCompareExpressionPredicate(CustomerFields.CustomerId, ComparisonOperator.Equal, _ New Expression(OrderFields.CustomerId)))), 1) Dim results As New DataTable() Dim adapter As New DataAccessAdapter() adapter.FetchTypedList(fields, results, Nothing)
' VB.NET .NET 2.0 Dim fields As New ResultsetFields(2) fields.DefineField(CustomerFields.CustomerID, 0) fields.DefineField(New EntityField2("NumberOfOrders", _ New ScalarQueryExpression(OrderFields.OrderId.SetAggregateFunction(AggregateFunction.Count), _ (CustomerFields.CustomerId = OrderFields.CustomerId))), 1) Dim results As New DataTable() Dim adapter As New DataAccessAdapter() adapter.FetchTypedList(fields, results, Nothing)